package com.xyzwps.lib.openapi.element;

/**
 * The format of schema value.
 *
 * @see <a href="https://json-schema.org/draft/2020-12/json-schema-validation#name-vocabularies-for-semantic-c">JSON schema validation: 7. Vocabularies for Semantic Content With "format"</a>
 * @see <a href="https://swagger.io/specification/#data-types">OpenAPI Specification: Data Types</a>
 */
public enum SchemaFormat {
    UNKNOWN(null),
    INT32(For.INTEGER),
    INT64(For.INTEGER),
    FLOAT(For.NUMBER),
    DOUBLE(For.NUMBER),
    PASSWORD(For.STRING),
    DATE_TIME(For.STRING),
    DATE(For.STRING),
    TIME(For.STRING),
    DURATION(For.STRING),
    EMAIL(For.STRING),
    IDN_EMAIL(For.STRING),
    HOSTNAME(For.STRING),
    IDN_HOSTNAME(For.STRING),
    IPV4(For.STRING),
    IPV6(For.STRING),
    URI(For.STRING),
    URI_REFERENCE(For.STRING),
    IRI(For.STRING),
    IRI_REFERENCE(For.STRING),
    UUID(For.STRING),
    URI_TEMPLATE(For.STRING),
    JSON_POINTER(For.STRING),
    RELATIVE_JSON_POINTER(For.STRING),
    REGEX(For.STRING);

    private final String value;
    private final For forType;

    SchemaFormat(For forType) {
        this.value = "UNKNOWN".equals(name())
                ? null
                : name().toLowerCase().replaceAll("_", "-");
        this.forType = forType;
    }

    public String value() {
        return value;
    }

    public For forType() {
        return forType;
    }

    public enum For {
        STRING,
        INTEGER,
        NUMBER
    }
}
